<?php

include './functions.php';

$data = $_POST;

$oldData = file_get_contents('./data/user.txt');
// 把json数据转成数组 
$oldData = json_decode($oldData,true);

foreach ($oldData as $v) {
	if($v['username']==$data['username']&&$v['password']==md5($data['password'])){

		$_SESSION['username'] = $data['username'];

		exit(json_encode(['error'=>0,'msg'=>'登录成功']));
	}
}

exit(json_encode(['error'=>1,'msg'=>'帐号或者密码不正确']));
